package com.chuanye.cluster.message;

import com.chuanye.cluster.pojo.SocketBaseDto;
import com.chuanye.cluster.pojo.SocketEnum;
import com.chuanye.cluster.utils.GsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Set;

@EnableScheduling //开启定时器功能
@Component
public class MessageSender {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private ServerConfig serverConfig;

    @Scheduled(fixedRate = 5000) //间隔5s
    public void sendMessage() {
        boolean isSend=false;
        String prefix=DevSignalController.pushDataKey+"_*";
        Set<String> setKeys = stringRedisTemplate.keys(prefix);
        for (String key : setKeys)
        {
             isSend=true;
             break;
        }
        if(true)
        {
            SocketBaseDto baseDto =new SocketBaseDto();
            baseDto.setSocketType(SocketEnum.push.getValue());
            String commandJson=GsonUtils.toJson(baseDto);
            DevSignalWebSocket.receiveMessage(commandJson);
        }

    }
}
